package com.ziJing.multithreading.sync;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @program Multithreading
 * @description:
 * 曾经的面试题：（淘宝？）
 * 实现一个容器，提供两个方法，add，size
 * 写两个线程，线程1添加十个元素到容器中，
 * 线程2实现监控元素的个数，当个数到5个时，线程2给出提示并结束
 * @author: zhangbo
 * @create: 2022/05/03 21:36
 */
public class T13_TestLockSupport {


    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                System.out.println(i);
                if(i == 5){
                    LockSupport.park();
                }


                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });


        t.start();

        TimeUnit.SECONDS.sleep(8);

        System.out.println("主线程继续执行了要....");
        LockSupport.unpark(t);

    }
}
